package org.ushio.nchu_22201408.controller;

import org.springframework.http.ResponseEntity;
import org.ushio.common_module.entity.BusinessInformation;
import org.ushio.nchu_22201408.Feign.BusinessInformationClient;
import org.ushio.common_module.entity.Bill;
import org.ushio.nchu_22201408.service.BillService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bills")
public class BillController {

    private final BillService billService;

    @Autowired
    private BusinessInformationClient businessInformationClient;
    @Autowired
    public BillController(BillService billService) {
        this.billService = billService;
    }

    @GetMapping("/getBusinessInformationByPhoneNumber")
    public ResponseEntity<BusinessInformation> getBusinessInformationByPhoneNumber(@RequestParam String phoneNumber){
        return  businessInformationClient.getBusinessInformationByPhoneNumber(phoneNumber);
    }

    @GetMapping("/all")
    public ResponseEntity<List<Bill>> getAllBillsByPhoneNumber(@RequestParam String phoneNumber) {
        System.out.println("666");
        List<Bill> bills = billService.findAllBillsByPhoneNumber(phoneNumber);
        return ResponseEntity.ok(bills);
    }
    @PostMapping("/create")
    public ResponseEntity<Bill> createBill(@RequestBody Bill bill) {
        Bill createdBill = billService.createBill(bill);
        return ResponseEntity.ok(createdBill);
    }
}